import Pages from '../../../pages/pages.vue'
import Save from './../save/save.vue'

import { setMenuType, getInvestLectureList, deleteinvestLecture, showMsg, investLectureItemTop } from '../../../../vuex/action'
export default {
  name: 'invest-lecture-list',
  components: {
    'vue-pages': Pages,
    'vue-save': Save
  },
  data() {
    return {
      cList: [],
      it: {
        startTime: '',
        endTime: ''
      },
      showSave: false,
      title: '',
    }
  },
  vuex: {
    getters: {
      fresh: state => state.inviteListFresh,
    },
    actions: {
      xSetMenuType: setMenuType,
      xGetInvestLectureList: getInvestLectureList,
      xDeleteinvestLecture: deleteinvestLecture,
      xTopItem: investLectureItemTop,
      xShowMsg: showMsg
    }
  },
  ready() {
    this.xSetMenuType('activity')
    this.getList({})
  },
  methods: {
    getList() {
      this.xGetInvestLectureList({
        start: 0,
        limit: 100000
      })
        .then((data) => {
          this.cList = data.list
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    saveItem(it, title) {
      this.showSave = true
      this.it = it
      this.title = title
    },
    deleteItem(id) {
      this.xDeleteinvestLecture({
        id: id
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    topItem(id, flag) {
      this.xTopItem({
        id: id,
        top: flag
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
